package edu.kaist.cs408.pof.android;

import android.content.Context;
import android.widget.SimpleAdapter;
import edu.kaist.cs408.pof.common.model.TalkVo;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/15/12
 * Time: 2:03 PM
 * To change this template use File | Settings | File Templates.
 */
public class TalkListAdaptor extends SimpleAdapter {
	private TalkListAdaptor(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
	}

	public static TalkListAdaptor getInstance(Context context, List<TalkVo> talks) {
		LinkedList<Map<String, Object>> talksListMap = new LinkedList<Map<String, Object>>();
		for (TalkVo talk : talks) {
			HashMap<String, Object> talkMap = new HashMap<String, Object>();
			talkMap.put("object", talk);
			talkMap.put("content", talk.getContent());
			talkMap.put("dish", talk.getDish() == null ? "" : "Dish " + talk.getDish().getName());
			talkMap.put("user", talk.getUser() == null ? "" : "User " + talk.getUser().getUsername());
			talkMap.put("restaurant", talk.getRestaurant() == null ? "" : "Restaurant " + talk.getRestaurant().getName());
			talksListMap.add(talkMap);
		}
		String from[] = new String[]{"content", "dish", "user", "restaurant"};
		int to[] = new int[]{R.id.contentTalkText, R.id.dishTalkText, R.id.userTalkText, R.id.restaurantTalkText};
		return new TalkListAdaptor(context, talksListMap, R.layout.talk_item, from, to);
	}
}
